<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>周记实-添加周记实</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="static/css/font.css">
    <link rel="stylesheet" href="static/css/xadmin.css">
    <link rel="stylesheet" href="static/lib/layui/css/layui.css">

    <style type="text/css">
        .layui-table th {
            text-align: center;
            font-weight: bold;
            min-width: 300px;
            max-width: 100px;
            border-style: solid;
            border-radius: 2px
        }
        .layui-table td {
            height: auto;
            line-height: 20px;
            padding: 0 10px;
            overflow: hidden;
            text-overflow: ellipsis;
            box-sizing: border-box;
            white-space: normal;   //nowrap=不换行   normal=正常
        }
    </style>

</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a >首页</a>
        <a >周记实</a>
        <a>
          <cite>添加周记实</cite>
        </a>
      </span>
</div>

<!-- f分割线 -->
<div class="layui-card-body">
    <div class="layui-fluid">


        <table class="layui-table">
            <thead>
            <tr>
                <th>周记实填写</th>
                <th  style="color: #FF0000;">岗位工作任务</th>

            </tr>
            </thead>
            <tbody id="view">
            <tr>
                <td id="weekGwzz">
                    <form class="layui-form" action="" lay-filter="example">
                        <ul class="addlmrlist-contanerbox">
                            <li id = "lmr-0">
                                <!--第几条周计划标识的隐藏域-->
                                <input type="hidden" value="1" id="weekNum0" name="weekNum">
                                <div class="layui-form-item">
                                    <label  class="layui-form-label layui-required" >日常工作</label>
                                    <div class="layui-input-block" style="width: 666px;">
                                        <textarea cols="20" rows="3" style="text-align: left;font: 16px 宋体;" type="text" name="weekInfo" id="weekInfo0" value="" lay-verify="" autocomplete="off" placeholder="请输入日常工作内容"  class="layui-textarea"></textarea>
                                    </div>
                                </div>
                                <hr style="border:none;border-top-width:5px;border-top-style:solid;border-top-color:#008B8B;" />
                            </li>
                        </ul>

                        <ul class="addlmrlist-contanerbox">
                            <li id = "zdgz-0">
                                <!--第几条周计划标识的隐藏域-->
                                <input type="hidden" value="1" id="zdgzNum0" name="zdgzNum">
                                <div class="layui-form-item">
                                    <label  class="layui-form-label layui-required" >重点工作</label>
                                    <div class="layui-input-block" style="width: 666px;">
                                        <textarea cols="20" rows="3" style="text-align: left;font: 16px 宋体;" type="text" name="zdgzInfo" id="zdgzInfo0" value="" lay-verify="" autocomplete="off" placeholder="请输入重点工作内容"  class="layui-textarea"></textarea>
                                    </div>
                                </div>
                                <hr style="border:none;border-top-width:5px;border-top-style:solid;border-top-color:#008B8B;" />
                            </li>
                        </ul>

                        <ul class="addlmrlist-contanerbox">
                            <li id = "cxgz-0">
                                <!--第几条周计划标识的隐藏域-->
                                <input type="hidden" value="1" id="cxgzNum0" name="cxgzNum">
                                <div class="layui-form-item">
                                    <label  class="layui-form-label layui-required" >创新工作</label>
                                    <div class="layui-input-block" style="width: 666px;">
                                        <textarea cols="20" rows="3" style="text-align: left;font: 16px 宋体;" type="text" name="cxgzInfo" id="cxgzInfo0" value="" lay-verify="" autocomplete="off" placeholder="请输入创新工作内容"  class="layui-textarea"></textarea>
                                    </div>
                                </div>
                                <hr style="border:none;border-top-width:5px;border-top-style:solid;border-top-color:#008B8B;" />
                            </li>
                        </ul>

                        <ul class="addlsrwlist-contanerbox">
                            <li id = "lsrw-0">
                                <!--第几条周计划标识的隐藏域-->
                                <input type="hidden" value="0" id="lsrwNum0" name="lsrwNum">
                                <div class="layui-form-item">
                                    <label  class="layui-form-label layui-required" >其他事项</label>
                                    <div class="layui-input-block" style="width: 666px;">
                                        <textarea cols="20" rows="3" style="text-align: left;font: 16px 宋体;" type="text" name="lsrwInfo" id="lsrwInfo0" value="" lay-verify="" autocomplete="off" placeholder="请输入其他工作内容"  class="layui-textarea"></textarea>
                                    </div>
                                </div>
                            </li>
                        </ul>

                        <div class="layui-input-inline">
                            <button class="layui-btn layui-btn-radius" lay-submit lay-filter="week-add-btn" style="width: 110px">提交</button>
                        </div>

                    </form>
                </td>
                <!--岗位职责-->
                <td>
                    <div id="gwzzInfo">

                    </div>
                </td>
            </tr>
            </tbody>
        </table>

    </div>
</div>



</body>
<script type="text/javascript" src="static/js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="static/lib/layui/layui.js"></script>
<script type="text/javascript" src="static/js/xadmin.js"></script>
<script>


    window.onload = function () {
        //初始加载员工个人的岗位职责
        var username = $("#username").val();
        var password = $("#password").val();
        /****/
         //加载周记实信息
         $.ajax({
             data: {
                 'username': username,
                 'password': password,
             },
            url:'empWeekInfo/selectGwzzinfo.do',
            dataType:'json',
            type:'post',
            success:function(result){
                 var content = result.rContent;
                 if(content == null || content == "null" || content == ""){
                     $("#gwzzInfo").html("");
                 }else{
                     $("#gwzzInfo").html(result.rContent);
                 }

            }
        });


    }
	  	
  	
    // 预先加载
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        
        
        
     	// 设置周计划递增初始值
        var lmrIndex = 0;//周计划
        var lmrNameIndex = 1;
     	
        var date = layui.laydate;
     	// 动态添加按钮
        layui.$('#newaddbtn').on('click', function () {
            var form = layui.form;
            // 递增序号
            
            lmrIndex++;
            lmrNameIndex++;
            if(lmrIndex > 2){
            	lmrIndex--;
                lmrNameIndex--;
                layer.alert("最多只能添加3个周计划");
            }else{
            	// id根据lmrIndex依次递增
                //使用下面这个Input
                var weekInfoList =
                    '<div class="layui-form-item">' +
                    '<label class="layui-form-label layui-required">周小节-' + lmrNameIndex + '</label>' +
                    '<div class="layui-input-block" style="width: 666px;">' +
                    '<textarea cols="20" rows="3" style="text-align: left;font: 16px 宋体;" type="text" name="weekInfo" id="weekInfo' + lmrIndex + '" value="" lay-verify="" autocomplete="off" placeholder="请简要输入周计划"  class="layui-textarea"></textarea>' +
                    '</div>' +
                    '</div>'
                    
                var finshLivelList =
                    '<div class="layui-form-item">' +
                    '<label class="layui-form-label layui-required">完成情况</label>' +
                    '<div class="layui-input-block" style="width: 666px;">' +
                    '<select id="finshLivel' + lmrIndex + '" value="" name="finshLivel" lay-verify=""  lay-filter="finshLivel" autocomplete="off" lay-search >' +
                    '   <option value="">请选择完成情况</option>' +
                    '   <option value="1">完成</option>' +
                    '   <option value="2">基本完成</option>' +
                    '   <option value="3" selected>未完成</option>' +
                    '</select>' +
                    '</div>' +
                    '</div><hr style="height:5px;border-color:#0000ff;"/>' 

                var weekNumList =
                    '<input type="hidden" value="'+lmrNameIndex+'" id="weekNum' + lmrIndex + '" name="weekNum">' 
               
                //删除先不加了,不生效
                var delList =
                    '<div className="form-content-sty" style="margin-left: 630px; margin-top: -95px">' +
                    '<button type="button" class="layui-btn layui-btn-danger layui-btn-sm removeclass" id="delbtns" οnclick="dellmr(\'lmr-' + lmrIndex + '\')">删除</button>' +
                    '</div><hr/><hr/>'
                    
                 // 注意 显示出来的顺序在这里设置，跟上面绘制的顺序无关
                var wholeList = '<li id="lmr-' + lmrIndex + '"><div class="lmr-card box-shadow">' + weekNumList + weekInfoList + finshLivelList +'</div></li>'
                $('.addlmrlist-contanerbox').append(wholeList);
                form.render();
            }
        });
     
     	
     	// 设置临时任务递增初始值
        var lsrwIndex = 0;//临时任务
        var lsrwNameIndex = 1;
        layui.$('#newaddTempbtn').on('click', function () {
            var form = layui.form;
            // 递增序号
            
            lsrwIndex++;
            lsrwNameIndex++;
            
            if(lsrwIndex > 2){
            	 lsrwIndex--;
                 lsrwNameIndex--;
                layer.alert("最多只能添加3个临时任务");
            }else{
            	// id根据lsrwIndex依次递增
  
                //使用下面这个Input
                var weekInfoList =
                    '<div class="layui-form-item">' +
                    '<label class="layui-form-label layui-required">临时任务-' + lsrwNameIndex + '</label>' +
                    '<div class="layui-input-block" style="width: 666px;">' +
                    '<textarea cols="20" rows="3" style="text-align: left;font: 16px 宋体;" type="text" name="lsrwInfo" id="lsrwInfo' + lsrwIndex + '" value="" lay-verify="" autocomplete="off" placeholder="请简要输入临时任务内容"  class="layui-textarea"></textarea>' +
                    '</div>' +
                    '</div>'
                    
                    
                var finshLivelList =
                    '<div class="layui-form-item">' +
                    '<label class="layui-form-label layui-required">完成情况</label>' +
                    '<div class="layui-input-block" style="width: 666px;">' +
                    '<select id="lsrwLivel' + lsrwIndex + '" value="" name="lsrwLivel" lay-verify=""  lay-filter="lsrwLivel" autocomplete="off" lay-search >' +
                    '   <option value="">请选择完成情况</option>' +
                    '   <option value="1">完成</option>' +
                    '   <option value="2">基本完成</option>' +
                    '   <option value="3" selected>未完成</option>' +
                    '</select>' +
                    '</div>' +
                    '</div><hr style="height:5px;border-color:#0000ff;"/>' 

                var weekNumList =
                    '<input type="hidden" value="'+lsrwNameIndex+'" id="lsrwNum' + lsrwIndex + '" name="lsrwNum">' 
               
                //删除先不加了,不生效
                var delList =
                    '<div className="form-content-sty" style="margin-left: 630px; margin-top: -95px">' +
                    '<button type="button" class="layui-btn layui-btn-danger layui-btn-sm removeclass" id="delbtns" οnclick="dellmr(\'lmr-' + lsrwIndex + '\')">删除</button>' +
                    '</div><hr/><hr/>'
                    
                 // 注意 显示出来的顺序在这里设置，跟上面绘制的顺序无关
                var wholeList = '<li id="lmr-' + lsrwIndex + '"><div class="lmr-card box-shadow">' + weekNumList + weekInfoList + finshLivelList +'</div></li>'
                $('.addlsrwlist-contanerbox').append(wholeList);
                form.render();
            }
        });
     
     
     
     	// 监听提交
        form.on('submit(week-add-btn)', function(data){
        	//日常工作
        	var addWeekData = [];
            for (var i = 0; i <= lmrIndex; i++) {
            	
            	//var weekNum = document.getElementById("weekNum" + i).value;//第几条周计划：从0开始
            	var weekInfo = document.getElementById("weekInfo" + i).value;//周计划内容
                //var finshLivel = document.getElementById("finshLivel" + i).value;//完成情况：1-完成;2-基本完成;3-未完成
                //var lsrwInfo = document.getElementById("lsrwInfo0").value;//临时任务暂先就一条吧
                //提交入参存在特殊符号，需要进行转义才可以
                weekInfo=weekInfo.replace(/\+/g, "%2B");
                weekInfo=weekInfo.replace(/%/g, "%25");
                weekInfo=weekInfo.replace(/&/g, "%26");

                addWeekData.push({
                	wFlag:"1",
                	weekInfo: weekInfo
                });
                
            }

            //重点工作
            var addZdgzData = [];
            for (var i = 0; i <= lmrIndex; i++) {

                //var weekNum = document.getElementById("weekNum" + i).value;//第几条周计划：从0开始
                var zdgzInfo = document.getElementById("zdgzInfo" + i).value;//周计划内容
                //var finshLivel = document.getElementById("finshLivel" + i).value;//完成情况：1-完成;2-基本完成;3-未完成
                //var lsrwInfo = document.getElementById("lsrwInfo0").value;//临时任务暂先就一条吧
                //提交入参存在特殊符号，需要进行转义才可以
                zdgzInfo=zdgzInfo.replace(/\+/g, "%2B");
                zdgzInfo=zdgzInfo.replace(/%/g, "%25");
                zdgzInfo=zdgzInfo.replace(/&/g, "%26");

                addZdgzData.push({
                    wFlag:"2",
                    zdgzInfo: zdgzInfo
                });

            }

            //创新工作
            var addCxgzData = [];
            for (var i = 0; i <= lmrIndex; i++) {

                //var weekNum = document.getElementById("weekNum" + i).value;//第几条周计划：从0开始
                var cxgzInfo = document.getElementById("cxgzInfo" + i).value;//周计划内容
                //var finshLivel = document.getElementById("finshLivel" + i).value;//完成情况：1-完成;2-基本完成;3-未完成
                //var lsrwInfo = document.getElementById("lsrwInfo0").value;//临时任务暂先就一条吧
                //提交入参存在特殊符号，需要进行转义才可以
                cxgzInfo=cxgzInfo.replace(/\+/g, "%2B");
                cxgzInfo=cxgzInfo.replace(/%/g, "%25");
                cxgzInfo=cxgzInfo.replace(/&/g, "%26");

                addCxgzData.push({
                    wFlag:"3",
                    cxgzInfo: cxgzInfo
                });

            }


          	//其他
        	var addTempData = [];
            for (var i = 0; i <= lsrwIndex; i++) {
            	//var weekNum = document.getElementById("lsrwNum" + i).value;//第几条周计划：从0开始
            	var lsrwInfo = document.getElementById("lsrwInfo" + i).value;//周计划内容
                //var lsrwLivel = document.getElementById("lsrwLivel" + i).value;//完成情况：1-完成;2-基本完成;3-未完成
                //提交入参存在特殊符号，需要进行转义才可以
                lsrwInfo=lsrwInfo.replace(/\+/g, "%2B");
                lsrwInfo=lsrwInfo.replace(/%/g, "%25");
                lsrwInfo=lsrwInfo.replace(/&/g, "%26");

                addTempData.push({
                	wFlag:"4",
                	tempOraryInfo: lsrwInfo
                    
                });
            }
        	
            //console.log("addWeekData="+JSON.stringify(addWeekData));
            //console.log("addTempData="+JSON.stringify(addTempData));

            $.ajax({
            	type: 'post',
                url: 'empWeekInfo/addWeekInfo.do',
                data: "listWeek="+JSON.stringify(addWeekData)
                    +"&listZdgz="+JSON.stringify(addZdgzData)
                    +"&listCxgz="+JSON.stringify(addCxgzData)
                    +"&listTemp="+JSON.stringify(addTempData),//将json数据转化为字符串
                dataType: 'json',
                success:function(result){
                	if(result.code==100){
                		 layer.alert("添加周记实成功", {
                             title: '添加周记实信息'
                         },
                         function () {
                             window.parent.location.reload();
                             var index = parent.layer.getFrameIndex(window.name);
                             parent.layer.close(index);
                         }
                     );
                	}else{
                		 layer.msg(result.message,{icon: 5,anim: 6});
                	}                            
                }
            });
            return false;
        });
    })
    
    //删除按钮
    function dellmr(id){
    	//alert("id="+id);
        var lmrIndex = id
        lmrIndex --;
        $("#"+id).remove();
    }
</script>
</html>
